void main() 
{
  // normal
  vec3 worldNormal = ComputeNormal();
    
  // couleur final
  vec4 resCol      = ComputeLighting(worldNormal); 
  
  float distance = vLength(vLocalPosition.xy);
  float fading = ComputeFading(distance, cb_Ground.u_RadiusRatio.x, cb_Ground.u_RadiusRatio.y);
  
  resCol.w *= fading;
 
#ifdef OutputIBLReflMap
  FRAGREFLECT.a *= fading;
#endif

#ifdef OutputNormalMap
  vec4 resNormal = vec4(1,1,1, 0); 
  resNormal = (vGetViewMatrix() * vec4(worldNormal,0)) * 0.5 + vec4(0.5);
  resNormal.w = 0.99 * ComputeFading(distance, cb_Ground.u_RadiusRatio.z, cb_Ground.u_RadiusRatio.w); // on ne met pas 1 pour pour pouvoir se servir de cette map pour differencier la scene 3D du plan et du fond
  FRAGNORMAL = resNormal;
#endif

#ifdef OutputF0RoughMap
#ifdef GROUND_MIRRORING
  FRAGMATPROP = vec4(cb_Ground.u_MirrorSpecularReflectance, cb_Ground.u_MirrorRoughness);
#else
  FRAGMATPROP = vec4(0.0);
#endif
#endif

#ifdef LogDepth
  gl_FragDepth  = vLog(-vViewPosition.z / vGetNearFarLogFactor().x) * vGetNearFarLogFactor().z;
#endif

#ifdef OutputWorldPos
  fragWorldPos.xyz = vec3(vGetViewInverseMatrix()  * vec4(vViewPosition.xyz, 1.0));
  fragWorldPos.w = uintBitsToFloat(compress_unit_vec(worldNormal));
#endif

#ifdef OutputMotionVectorMap
	fragMotionVector = vGetMotionVector();
#endif

  //Result
	FRAGCOLOR = resCol; 
}
